<template>
  <div :class="{
    'vux-flex-col': orient === 'vertical',
    'vux-flex-row': orient === 'horizontal'
  }"
       :style="styles"
       class="vux-flexbox">
    <slot name="default"></slot>
  </div>
</template>

<script setup>
import {
  computed,
  nextTick,
  onBeforeUnmount,
  onMounted,
  reactive,
  watch, toRef, toValue, provide
} from "vue";

defineOptions({
  name: 'Flexbox',
})
const props = defineProps({
  gutter: {
    type: Number,
    default: 8
  },
  orient: {
    type: String,
    default: 'horizontal'
  },
  justify: String,
  align: String,
  wrap: String,
  direction: String
})

const styles = computed(() => {
  const styles = {
    'justify-content': props.justify,
    '-webkit-justify-content': props.justify,
    'align-items': props.align,
    '-webkit-align-items': props.align,
    'flex-wrap': props.wrap,
    '-webkit-flex-wrap': props.wrap,
    'flex-direction': props.direction,
    '-webkit-flex-direction': props.direction
  }
  return styles
})


const parentGutter  = "parentGutter"
const parentOrient  = "parentOrient"
provide('parentGutter', props.gutter)
provide('parentOrient', props.orient)


</script>

<script>
export default {
  // name: 'Flexbox',
  // props: {},
  // computed: {
    // styles() {
    //   const styles = {
    //     'justify-content': this.justify,
    //     '-webkit-justify-content': this.justify,
    //     'align-items': this.align,
    //     '-webkit-align-items': this.align,
    //     'flex-wrap': this.wrap,
    //     '-webkit-flex-wrap': this.wrap,
    //     'flex-direction': this.direction,
    //     '-webkit-flex-direction': this.direction
    //   }
    //   return styles
    // }
  // }
}
</script>

<style lang="scss">
.vux-flexbox {
  width: 100%;
  text-align: left;
  display: flex;
  display: -webkit-flex;
  box-align: center;
  align-items: center;
  //box-sizing:border-box 就是为了设置width和height元素值包含padding(内边距)和border(边框)的值，这样就很好的解决了padding使宽度溢出的问题
  box-sizing:border-box;
  .vux-flexbox-item {
    flex: 1;
    -webkit-flex: 1;
    min-width: 20px;
    width: 0%;
    &:first-child {
      margin-left: 0 !important;
      margin-top: 0 !important;
    }
  }
}

.vux-flex-row {
  box-direction: row;
  box-orient: horizontal;
  flex-direction: row;
}

.vux-flex-col {
  box-orient: vertical;
  flex-direction: column;
  > .vux-flexbox-item {
    width: 100%;
  }
}
</style>
